package com.kxq.zhuoyue.controller;


import com.kxq.zhuoyue.po.ConversationGroup;
import com.kxq.zhuoyue.service.ConversationGroupService;
import com.kxq.zhuoyue.util.UUID;
import com.kxq.zhuoyue.util.result.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xjh
 * @since 2023-09-04
 */
@RestController
@RequestMapping("/conversationGroup")
public class ConversationGroupController {

    @Autowired
    private ConversationGroupService conversationGroupService;

    /**\
     * 获取分组
     * @return
     */
    @PostMapping("/selectAll")
    public AjaxResult selectAll(){
        List<ConversationGroup> list = conversationGroupService.list();
        return AjaxResult.success(list);
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody ConversationGroup conversationGroup){
        String id = UUID.getOrderIdByTime();
        conversationGroup.setConversationGroupId(id);
        boolean save = conversationGroupService.save(conversationGroup);
        if (save){
            return AjaxResult.success("新增分组成功 ！");
        }
        else {
            return AjaxResult.success("新增分组失败 !");
        }
    }

    @PostMapping("/delete/{conversationGroupId}")
    public AjaxResult delete(@PathVariable String conversationGroupId){
        boolean b = conversationGroupService.removeById(conversationGroupId);
        if (b){
            return AjaxResult.success("删除分组成功 ！");
        }
        else {
            return AjaxResult.success("删除分组失败 !");
        }
    }

}

